

library httpplugin;

import 'dart:convert';
import '../event_bus_notify_keys/event_bus_notify_keys.dart';
import 'package:flutter_tool/flutter_tool.dart';
import 'package:dio/dio.dart';
import 'containers.dart';
import 'package:httpplugin/httpplugin.dart';



part 'http_channel_extension.dart';
part 'wrapper.dart';
part 'http_channel_mixin.dart';
part 'paging_mixin.dart';

typedef Failure = void Function(String);
typedef Success = void Function();

/// 请求管道
class HttpChannel with HttpChannelMixin {

  /// 获取Ip
  String get ip => HttpMidBuffer.buffer.ip;

  /// 获取 端口
  String get port => HttpMidBuffer.buffer.port;

  /// 获取 token
  String get accessToken => HttpMidBuffer.buffer.accessToken;

  /// 刷新token
  String get refreshToken => HttpMidBuffer.buffer.refreshToken;

  /// 作用域
  List<String> get scopes => HttpMidBuffer.buffer.scopes;

  /// 超时时间
  DateTime get expireDateTime => HttpMidBuffer.buffer.expireDateTime;

  /// 启动
  Future<void> setUpChannel(
      {HttpConfig config = const HttpConfig(),
        bool connectivity = false,
        void Function()? connectivityChange,
        CacheBase? cache,
        ClientData? clientData, EventNotifyClass? eventListener,
        ExceptionCollectAbstract? exceptionCollect}) async {
    /// 启动
    await HttpMidBuffer.setUpMidBuffer(
        config: config,
        connectivity: connectivity,
        connectivityChange: connectivityChange,
        cache: cache, exceptionCollect: exceptionCollect,
        clientData: clientData, eventListener: eventListener);
    return;
  }

  /// 添加任务(挂载)
  void addTickContainer(HttpTickContainer Function() container, String key) {
    HttpMidBuffer.buffer.addTickContainer(container, key);
  }

  /// 启动task mount
  void setUpTaskMount(Map<String, HttpTickContainer Function()> map) {
    HttpMidBuffer.buffer.setUpTaskMount(map);
  }

  /// 添加任务
  void addTickContainers(Map<String, HttpTickContainer Function()> ticks) {
    HttpMidBuffer.buffer.addTickContainers(ticks);

  }

  /// 更新设置
  void updateMidBuffer({required HttpConfig config}){
    HttpMidBuffer.buffer.updateMidBuffer(config: config);
  }
}